﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
            font-size: 14px;
        }

        #l-map {
            height: 700px;
            width: 100%;
        }

        #r-result {
            width: 100%;
        }
    </style>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=E6fLfoZvafshmZ0srkPPo9Iu2f8xOZHa"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=E6fLfoZvafshmZ0srkPPo9Iu2f8xOZHa"></script>
    <script src="~/libs/jquery/jquery.js"></script>
    <title>关键字输入提示词条</title>
</head>
<body>
    <div id="r-result">
        请输入:
        <input type="text" id="suggestId" size="30" value="" style="width:300px;" />
        <input type="text" id="endsite" size="30" value="" style="width:300px;" />
        <input type="button" value="查询" id="search" />
    </div>
    <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
    <div id="l-map" style="margin:15px 0 15px 0;"></div>

</body>
</html>
<script type="text/javascript">
    $(function () {
        $("#search").click(function () {
            setmap();
        });
    });

    // 百度地图API功能
    function G(id) {
        return document.getElementById(id);
    }

    var map = new BMap.Map("l-map");
    map.centerAndZoom("北京", 12);// 初始化地图,设置城市和地图级别。

    var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {
            "input": "suggestId"
            , "location": map
        });

    ac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel").innerHTML = str;

    });

    var endac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {
            "input": "endsite"
            , "location": map
        });

    endac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel").innerHTML = str;

    });

    function setmap() {
        var map = new BMapGL.Map("l-map");
        map.enableScrollWheelZoom();
        map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);
        var walking = new BMapGL.WalkingRoute(map, { renderOptions: { map: map, autoViewport: true } });
        //walking.search('西单', '慈云寺');
        var bcity = document.getElementById("suggestId").value;
        var ecity = document.getElementById("endsite").value;
        walking.search(bcity, ecity);
    }
</script>

